<template>
    <div class="virtual_member_use_detail">
        <el-card shadow="never" class="card-com" style="margin-top: 10px;">
            <div class="card-1">
                <searchPanel @refresh="getData('reset')" >
                    <!-- 查询面板 -->
                    <template v-slot:search>
                        <el-form :inline="true" :model="listSearch" class="demo-form-inline" label-width="120px">
                            <el-row :gutter="20">
                                <el-col :xs="24" :sm="12" :sd="12" :lg="8" :xl="6">
                                    <el-form-item label="权益包名称">
                                        <NormalInput v-model:model-value="listSearch.condition.packageName"
                                            @get-data="getData('search')"></NormalInput>
                                    </el-form-item>
                                </el-col>

                                <el-col :xs="24" :sm="12" :sd="12" :lg="8" :xl="6">
                                    <el-form-item label="权益包编码">
                                        <NormalInput v-model:model-value="listSearch.condition.packageCode"
                                            @get-data="getData('search')"></NormalInput>
                                    </el-form-item>
                                </el-col>



                            </el-row>
                            <el-row justify="end">
                                <el-button type="primary" @click="getData('search')">查询</el-button>
                                <el-button @click="getData('reset')">重置</el-button>
                            </el-row>
                        </el-form>
                    </template>
                    <!-- 字段添加 -->
                    <template v-slot:edit>
                        <el-button :icon="Plus" type="primary" @click="AddEdit('add')"></el-button>
                        <DropItem v-model:table-prop="tableProp"></DropItem>
                    </template>
                </searchPanel>
            </div>
            <div class="card-2">
                <!-- table数据 -->
                <OnlyTable ref="onlyTableRef" class="card-2" :tableProps="tableProp" :pageTotal="pageParams.total"
                    @get-page="handPage" :tableData="pageParams.tableData" :tableHeight="pageParams.tableHeight"
                    :loading="pageParams.loadIng">
                    <template #handle="scope">
                        <el-button link type="primary" @click="AddEdit('edit', scope.row)">编辑</el-button>
                        <el-button link type="danger" @click="delBtn(scope.row)">删除</el-button>
                        <el-button link type="primary" @click="detailBtn(scope.row)">详情</el-button>
                    </template>
                </OnlyTable>
            </div>
        </el-card>
        <addPackage ref="packageRef" @refresh="getData('reset')" @search-edit="getData('search')"></addPackage>
        <lookShow ref="loopRef"></lookShow>
    </div>
</template>

<script setup lang="ts">
import { storeToRefs } from 'pinia';
import { onMounted, ref, nextTick, onUnmounted, defineAsyncComponent } from 'vue';
import { Search, Plus, Refresh, Download } from '@element-plus/icons-vue'
import { packageListStore } from "./pageStore"
import _ from "lodash"
import { useComListData } from "@/store/list"
const onlyTableRef = ref()
const addPackage = defineAsyncComponent(() => import("./component/addAndEdit.vue"))
const lookShow = defineAsyncComponent(() => import("./component/look.vue"))
const { getEquityPortfolioList } = useComListData()

const { detailData, tableProp, listSearch, pageParams, detailRef, packageRef, loopRef } = storeToRefs(packageListStore())

const { getDate1, handPage, delBtn, detailBtn, quotaBtn, AddEdit } = packageListStore()

onMounted(() => {
    getDate1('reset')
    nextTick(() => {
        const dom1 = document.querySelector(".card-1") as any;
        const dom2 = document.querySelector(".card-com") as any;
        if (dom2) {
            const height = dom2.offsetHeight - dom1.offsetHeight - 70;
            pageParams.value.tableHeight = height;
        }
    })
    getEquityPortfolioList()
})


const getData = (type: string) => {
    if (type == 'reset') onlyTableRef.value.initPagination()
    getDate1(type)
}
</script>

<style scoped lang="scss">
.virtual_member_use_detail {
    height: calc(100vh - 156px);


    .card-com {
        display: flex;
        flex-direction: column;

        .card-2 {
            flex-grow: 1;
        }
    }
}
</style>